import Vue from "vue";
import Router from "vue-router";
Vue.use(Router);

// 引入多个模块的规则
import questionsRouter from "./modules/questions";
import backRouter from "./modules/backsatge";
import companyRouter from "./modules/company";
import interviewRouter from "./modules/interview";
import subjectRouter from "./modules/subject";
// 动态路由
export const asyncRoutes = [
  backRouter,
  companyRouter,
  questionsRouter,
  subjectRouter,
  interviewRouter,

];

/* Layout */
// 导入布局组件
import Layout from "@/layout";
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "面板", icon: "dashboard" },
      },
    ],
  },


];
// 创建一个路由实例，并返回
const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: [...constantRoutes], // 只有静态
  });
// 获取到路由实例
const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
// 重置一个路由实例
export function resetRouter() {
  // 创建一个新的路由实例
  const newRouter = createRouter();
  // 将路由实例的matcher变成新的即可
  router.matcher = newRouter.matcher; // reset router
}

export default router;
